<template>
  <div>
    <!-- 展示表格 -->
    <el-table style="width: 100%" border :data="records">
      <el-table-column type="index" label="序号" width="80px" align="center"></el-table-column>
      <el-table-column prop="skuName" label="名称" width="width"></el-table-column>
      <el-table-column prop="skuDesc" label="描述" width="width"></el-table-column>
      <el-table-column label="默认图片" width="110px">
        <template slot-scope="{row}">
          <img :src="row.skuDefaultImg" alt="" style="width:80px; height:80px">
        </template>
      </el-table-column>
      <el-table-column prop="weight" label="重量" width="80px"></el-table-column>
      <el-table-column prop="price" label="价格" width="80px"></el-table-column>
      <el-table-column prop="porp" label="操作" width="width">
        <template slot-scope="{row}">
          <el-button type="success" size="mini" icon="el-icon-top" v-if="row.isSale == 0" @click="AddedGoods(row)">
          </el-button>
          <el-button type="info" size="mini" icon="el-icon-bottom" @click="UnShelveGoods(row)" v-else></el-button>
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="AwaitAlter(row)"></el-button>
          <el-button type="info" size="mini" icon="el-icon-info" @click="lookSkuInfo(row)"></el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteSkuGoods(row)"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页器 @size-change="分页器每页展示发生变化" @current-change="分页器点击页数发送变化"  -->
    <el-pagination style="text-align: center;" :current-page.sync="page" :page-sizes="[3, 5, 10]" :page-size="limit"
      layout="prev,pager,next,jumper,->,sizes,total" :total="total" @size-change="handleSizeChange"
      @current-change="getSkuList">
    </el-pagination>

    <!-- 抽屉 -->
    <el-drawer :visible.sync="show" size="50%">
      <el-row>
        <el-col :span="5"><b>名称</b></el-col>
        <el-col :span="16">{{ skuInfo.skuName }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5"><b>描述</b></el-col>
        <el-col :span="16">{{ skuInfo.skuDesc }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5"><b>价格</b></el-col>
        <el-col :span="16">{{ skuInfo.price }}元</el-col>
      </el-row>
      <el-row>
        <el-col :span="5"><b>平台属性</b></el-col>
        <el-col :span="16">
          <template>
            <el-tag type="success" style="margin: 0px 5px" v-for="arrt in skuInfo.skuAttrValueList" :key="arrt.id">
              {{ arrt.attrId }}:{{ arrt.valueId }}
            </el-tag>
          </template>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5"><b>商品图片</b></el-col>
        <el-col :span="16">
          <!--走马灯组件  -->
          <el-carousel height="150px" arrow="never">
            <el-carousel-item v-for="item in skuInfo.skuImageList" :key="item.id"> 
              <img :src="item.imgUrl" alt="" style="width: 100%; height: 300px;">
            </el-carousel-item>
          </el-carousel>
        </el-col>
      </el-row>
    </el-drawer>

  </div>
</template>

<script>
export default {
  name: 'Sku',
  data() {
    return {
      // 分页器
      // 当前页数
      page: 1,
      // 总共数据
      total: 0,
      // 默认展示多少条数据
      limit: 5,
      // sku列表数据
      records: [],
      // 控制抽屉组件显示|隐藏
      show: false,
      // 详情页的数据展示
      skuInfo: {}
    }
  },
  mounted() {
    // 发送请求获取参数
    this.getSkuList();
  },
  methods: {
    // 获取页面数据函数
    async getSkuList(pager = 1) {
      this.page = pager;
      let result = await this.$API.sku.reqSkuInfoList(this.page, this.limit);
      if (result.code == 200) {
        // 存储数据
        this.total = result.data.total
        this.records = result.data.records
      }
    },

    // 点击每页展示多少条数据发生变化
    handleSizeChange(limit) {
      // 修改参数
      this.limit = limit;
      // 发送请求
      this.getSkuList();
    },

    // 商品上架
    async AddedGoods(row) {
      // 发请求，通知服务器上架。
      let result = await this.$API.sku.reqAdded(row.id);
      if (result.code == 200) {
        row.isSale = 1;
        this.$message.success("下架成功");
      }
    },

    // 商品下架
    async UnShelveGoods(row) {
      // 发请求
      let res = await this.$API.sku.reqUnShelve(row.id);
      if (res.code == 200) {
        row.isSale = 0;
        this.$message.success("上架成功");
      }
    },

    // 商品修改
    AwaitAlter(rwo) {
      this.$message("还在后续开发中");
    },

    // 查看sku商品详情的回调
    async lookSkuInfo(row) {
      // 显示抽屉
      this.show = true;
      // 发请求，
      let res = await this.$API.sku.reqSkuInfo(row.id);
      if (res.code == 200) {
        // 存储结果
        this.skuInfo = res.data;
      }
    },

    //删除点击某一个商品的回调
    deleteSkuGoods() { }

  }
}
</script>

<style>
.el-carousel__item {
  color: #1266d4;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
}

/* 修改跑马灯样式 */
.el-carousel__button {
  width: 10px;
  height: 10px;
  background-color: rgb(156, 168, 173);
  border-radius: 50%;
}

.el-carousel__item:nth-child(2n) {
  background-color: #dde4ec;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d0d7df;
}
</style>

<style scoped>
.el-row .el-col-5 {
  font-size: 18px;
  text-align: right;
}

.el-col {
  margin: 10px 10px;
  line-height: 30px;
}
</style>